/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */
#pragma once

#include <lib3d/Math_lib3d.h>
#include <math/Frustrum.h>
#include "Node.h"
#include "Factory.h"
#include <lib3d/CameraDesc.h>
#include <lib3d/hard/RenderTarget.h>

namespace liba
{
namespace lib3d
{
namespace node
{

class Camera : public Node
{
	NODE_DEFINITION(Camera)
public:
	Camera( const Atom & name, Node * parent );
	virtual ~Camera();

	// Attributes...
	static const Atom near_plane_name;
	static const Atom far_plane_name;
	static const Atom fog_color_name;
	static const Atom fog_range_name;

	bool start_render_to_list( hard::Hardware * hardware, hard::RenderList * render_list );
//	bool render( hard::Hardware * hardware, hard::RenderTarget * render_target );
	/** this method modifies desc, that's why no const */
	const CameraDesc & get_desc();
	void change_viewport( const Viewport & viewport );
	virtual Ray get_world_ray(double ray_x, double ray_y)=0;
	static Camera * active_camera();
	virtual bool ortho_projection()
	{
		return false;
	}

	virtual void CreateProxy(ProxyVisitor * proxyVisitor);
protected:
	virtual bool on_attribute( xml::Provider * prov, const std::string & name, const std::string & value );
	virtual void on_save_attributes( xml::SaverBase * saver )const;
	virtual bool on_end_node( xml::Provider * prov );

	virtual void on_change_parameters()=0;

	CameraDesc desc;
	
	static Camera * active_rendering_camera;

protected:
	template<class T>
	void OnChangeParameters( T )
	{
		on_change_parameters();
	}
};


inline void Camera::change_viewport( const Viewport & viewport )
{
	desc.viewport = viewport;
}

} // namespace node
} // namespace lib3d
} // namespace liba
using namespace liba;

